layui.use(['table', 'admin', 'ax','form'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var form = layui.form;

    /**
     * 库位表管理
     */
    var BasicPosition = {
        tableId: "basicPositionTable"
    };

    /**
     * 初始化表格的列
     */
    BasicPosition.initColumn = function () {
        return [[
            {field: 'id', hide: true, title: '主键'},
            {align: 'center', toolbar: '#tableBar', title: '操作', width: 80},
            {field: 'positionAreaName', sort: true, title: '库区'},
            {field: 'positionNumber', sort: true, title: '库位编号', style:'color: #2b85e4;font-weight: 600;'},
            {field: 'positionType', sort: true, title: '库位类型'},
        ]];
    };

    /**
     * 点击查询按钮
     */
    BasicPosition.search = function () {
        var queryData = {};
        queryData['condition'] = $("#condition").val();
        queryData['positionType'] = $("#positionType").val();
        table.reload(BasicPosition.tableId, {
            where: queryData, page: {curr: 1},
             done:function () {
            }
        });
    };
    
    // 渲染表格
    var tableResult = table.render({
        elem: '#' + BasicPosition.tableId,
        url: Feng.ctxPath + '/basicPosition/list?WarehouseId='+Feng.getUrlParam("warehouseId")+'&positionState=1',
        page: true,
        limit: 60,
		limits:[60,120,240,360,480,1500,5000],
        height: "full-60",
        cellMinWidth: 100,
        toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
        totalRow: true ,//开启合计行
        defaultToolbar: ['filter', 'exports', 'print'],
        cols: BasicPosition.initColumn()
    });

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        BasicPosition.search();
    });
    
    //回填商品数据
    function confirm(data){
    	parent.BasicPositionInfoDlg.data.id = data.id;
    	parent.BasicPositionInfoDlg.data.positionNumber = data.positionNumber;
    	parent.BasicPositionInfoDlg.data.positionAreaId = data.positionAreaId;
    	var Index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(Index);
    }
    
    // 双击行事件
    table.on('rowDouble(' + BasicPosition.tableId + ')', function (obj) {
        var data = obj.data;
    	confirm(data);
    });

    // 工具条点击事件
    table.on('tool(' + BasicPosition.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if (layEvent === 'confirm') {
        	confirm(data);
        } 
    });

    //返回按钮
    $("#backupPage").click(function () {
    	var Index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(Index);
    });
    
});
